import http from '@/http';
import {
  ProblemSet,
  ProblemSetProblem,
  CreateProblemSetRequest,
  UpdateProblemSetRequest,
  AddProblemRequest,
  RemoveProblemRequest,
  UpdateProblemOrderRequest,
  ProblemSetListParams,
  ProblemSetListResponse,
  LeaderboardData,
} from '@/types/problemSet';

export const problemSetService = {
  // 获取题单列表
  getProblemSets: (params: ProblemSetListParams = {}) => {
    return http.get<ProblemSetListResponse>('/api/problem-sets/', { params });
  },

  // 获取题单详情
  getProblemSet: (id: number) => {
    return http.get<ProblemSet>(`/api/problem-sets/${id}/`);
  },

  // 创建题单
  createProblemSet: (data: CreateProblemSetRequest) => {
    return http.post<ProblemSet>('/api/problem-sets/', data);
  },

  // 更新题单
  updateProblemSet: (id: number, data: UpdateProblemSetRequest) => {
    return http.patch<ProblemSet>(`/api/problem-sets/${id}/`, data);
  },

  // 删除题单
  deleteProblemSet: (id: number) => {
    return http.delete(`/api/problem-sets/${id}/`);
  },

  // 获取题单中的题目列表
  getProblemSetProblems: (id: number) => {
    return http.get<ProblemSetProblem[]>(`/api/problem-sets/${id}/problems/`);
  },

  // 添加题目到题单
  addProblemToSet: (id: number, data: AddProblemRequest) => {
    return http.post(`/api/problem-sets/${id}/add_problem/`, data);
  },

  // 从题单中移除题目
  removeProblemFromSet: (id: number, data: RemoveProblemRequest) => {
    return http.delete(`/api/problem-sets/${id}/remove_problem/`, { data });
  },

  // 更新题目顺序
  updateProblemOrder: (id: number, data: UpdateProblemOrderRequest) => {
    return http.post(`/api/problem-sets/${id}/update_problem_order/`, data);
  },

  // 获取题单排行榜
  getLeaderboard: (id: number) => {
    return http.get<LeaderboardData>(`/api/problem-sets/${id}/leaderboard/`);
  },
}; 